

public class QuickSort {

	public static void main(String[] args) {
		
		int[] v = { 18, 4, 7, 54, 8, 563, 3, 5, 568,4, 9, 76, 6,4 };
		long start, stop;
		start = System.nanoTime();
		quickSort(v,0,v.length);		stop = System.nanoTime();
		System.out.println("TEMPO: " + (stop - start) + " nanosegs");
		printVector(v);

	}

	public static void printVector(int[] iVector) {
		for (int i = 0; i < iVector.length; i++) {
			System.out.print(iVector[i] + ",");
		}
	}


	
	public static void quickSort(int v[],int ini,int fim){
		int posPivo;
		
		if(ini<fim){
			
			int valorPivo;
			valorPivo = v[ini];
			posPivo = ini;
			
			for(int i=ini+1;i<fim;i++){
				
				if(v[i]<valorPivo){
					
					v[posPivo]=v[i];
					posPivo++;
					v[i]=v[posPivo];					
					v[posPivo]=valorPivo;
					
				}
			}
			quickSort(v,ini,posPivo);
			quickSort(v,posPivo+1,fim);
		}
	}
}
